package com.yanqu.road.server.cmd.beauty;

import com.yanqu.road.server.pb.BeautyPb;
import com.yanqu.road.entity.player.UserBeauty;
import com.yanqu.road.pb.beauty.BeautyProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.BeautyModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.server.command.Cmd;


@Cmd(code = Protocol.S_BEAUTY_PROMOTION, desc = "美女晋升")
public class BeautyPromotionCmd extends AbstractCommand {
    private int beautyId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        BeautyProto.BeautyPromotionReqMsg req = BeautyProto.BeautyPromotionReqMsg.parseFrom(packet.getBytes());
        beautyId = req.getBeautyId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(BeautyModule.class).beautyPromotion(beautyId);
    }

    @Override
    public void sendData(GamePlayer player) {
        BeautyProto.BeautyPromotionRespMsg.Builder respMsg = BeautyProto.BeautyPromotionRespMsg.newBuilder();
        respMsg.setRet(ret);
        if(0 == ret){
            UserBeauty userBeauty = player.getModule(BeautyModule.class).getUserBeauty(beautyId);
            BeautyProto.BeautyTempMsg.Builder beautyMsg = BeautyPb.parseBeautyTempMsg(userBeauty);
            if(null != beautyMsg){
                respMsg.setBeauty(beautyMsg);
            }
        }
        player.sendPacket(Protocol.U_BEAUTY_PROMOTION, respMsg);
    }
}
